package com.example.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.example.pojo.fixtureListPojo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface fixtureListMapp {
    @DS("newMscLowCodeFormal")
    @Insert("insert into ddm_fixture_list (" +
            "id, create_time, update_time, " +
            "creator, process_status, sys_update_user, " +
            "sys_audit_user, sys_audit_time, sys_deleted, " +
            "workshop, department, equipment_name, " +
            "line, op, measurement_project, " +
            "drawing_number, measurement_standard, measurement_type, " +
            "standard_value, upper_tolerance, lower_tolerance, " +
            "model, measurement_technique, cycle, " +
            "fixture_number) " +
            "values (" +
            "#{id}, #{create_time}, #{update_time}, " +
            "#{creator}, #{process_status}, #{sys_update_user}, " +
            "#{sys_audit_user}, #{sys_audit_time}, #{sys_deleted}, " +
            "#{workshop}, #{department}, #{equipment_name}, " +
            "#{line}, #{op}, #{measurement_project}, " +
            "#{drawing_number}, #{measurement_standard}, #{measurement_type}, " +
            "#{standard_value}, #{upper_tolerance}, #{lower_tolerance}, " +
            "#{model}, #{measurement_technique}, #{cycle}, " +
            "#{fixture_number})")
    void insertOne(fixtureListPojo pojo);

    //查询工装台账中所有的数据
    @DS("newMscLowCodeFormal")
    //*代表所有字段
    @Select("select * from ddm_fixture_list where sys_deleted=0 order by line, op")
    List<fixtureListPojo> queryAll();

    //根据ID，选择一行数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_fixture_list where id=#{id}")
    fixtureListPojo selectById(String id);

    //根据IdUse编辑某一行数据
    //指定数据库
    @DS("newMscLowCodeFormal")
    //更新哪些字段的数据
    @Update("update ddm_fixture_list " +
            "set " +
            "id=#{id}, " +
            "create_time=#{create_time}, " +
            "update_time=#{update_time}, " +
            "creator=#{creator}, " +
            "process_status=#{process_status}, " +
            "sys_update_user=#{sys_update_user}, "+
            "sys_audit_user=#{sys_audit_user}, " +
            "sys_audit_time=#{sys_audit_time}, " +
            "sys_deleted=#{sys_deleted}," +
            "workshop=#{workshop}, " +
            "department=#{department}, " +
            "equipment_name=#{equipment_name}, " +
            "line=#{line}, " +
            "op=#{op}, " +
            "measurement_project=#{measurement_project}, " +
            "drawing_number=#{drawing_number}, " +
            "measurement_standard=#{measurement_standard}, " +
            "measurement_type=#{measurement_type}, " +
            "standard_value=#{standard_value}, " +
            "upper_tolerance=#{upper_tolerance}, " +
            "lower_tolerance=#{lower_tolerance}, " +
            "model=#{model}, " +
            "measurement_technique=#{measurement_technique}, " +
            "cycle=#{cycle}, " +
            "fixture_number=#{fixture_number} " +
            "where id=#{id}")
    void editOneByIdUse(fixtureListPojo pojo);

    //查询某一字段为某值的数据
    @DS("newMscLowCodeFormal")
    @Select("select * from ddm_fixture_list " +
            "where sys_deleted=0 and ${fieldName}=#{fieldValue}")
    List<fixtureListPojo> queryOneField(String fieldName, String fieldValue);

    //对一个字段，从老值更改为新值
    @DS("newMscLowCodeFormal")
    @Update("update ddm_fixture_list set ${fieldName}=#{newData} where ${fieldName}=#{old}")
    void editByField(String fieldName, String old, String newData);
}
